<?php
namespace app\controller\open;

use app\exception\ErrnoPlus;
use app\service\HelpProblemInfoService;
use app\validate\HelpProblemInfoValidate;

class HelpProblemInfoController extends BaseOpenController{

    protected $beforeActionList = [
    ];
    public function initValidate(){
        $this->validate = new HelpProblemInfoValidate();
    }

    public function hot_list_action(){
        $input = $this->check();        
        $hotList = HelpProblemInfoService::getHotBaseInfoList(['language'=> strtoupper($input['lang'])]);  
        return self::ok($hotList);
    }

    public function type_list_action(){
        $input = $this->check();
        $type = $input['type'];
        $language = strtoupper($input['lang']);
        $res = HelpProblemInfoService::getAllByType(["type" => $type, "language" => $language]); 
        $info["problemList"] = $res;      
        $info["total"] = count($res);
        return self::ok(['info'=>$info]);
    }

    public function detail_action(){
        $input = $this->check();
        $id = $input['id'];
        $detail =  HelpProblemInfoService::detail($id);
        if(empty($detail)){
         
            return self::fail("no data",ErrnoPlus::NOT_BACK_DATA);  
        }    
        HelpProblemInfoService::addVisit($detail['id']);
        return self::ok($detail);  
    }
}